﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkStation.UI.Controls
{
    public class PieMotion : MotionShape
    {
        public PointF CenterPoint;
        public double Radius;
        public float StartAngle;
        public float EndAngle;
        public Color SecondColor { get; set; }
        public bool IsCCW { get; set; }
        public PieMotion()
        {

        }
        public PieMotion(string description)
            : base(description)
        {

        }
        public override void Draw(Graphics g)
        {
            Pen circlepen = new Pen(PaintColor, LineWidth);
            if (Radius < 0)
                return;
            int squarewidth = (int)(2 * Radius);
            float start = 0;
            float end = 0;
            if (IsCCW)
            {
                start = 360 - EndAngle;
                end = StartAngle < 0 ? -StartAngle : 360 - StartAngle;
                if (squarewidth == 0)
                    return;
                g.FillPie(new SolidBrush(Color.FromArgb(Alpha, FillColor)),
                          new Rectangle((int)(CenterPoint.X - squarewidth / 2),
                                        (int)(CenterPoint.Y - squarewidth / 2),
                                        squarewidth,
                                        squarewidth),
                          start,
                          EndAngle - StartAngle);

                g.FillPie(new SolidBrush(Color.FromArgb(Alpha, SecondColor)),
                          new Rectangle((int)(CenterPoint.X - squarewidth / 2),
                                        (int)(CenterPoint.Y - squarewidth / 2),
                                        squarewidth,
                                        squarewidth),
                          end,
                          360 - (EndAngle - StartAngle));
            }
            else
            {
                start = StartAngle < 0 ? 360 + StartAngle : StartAngle;
                end = EndAngle - StartAngle;
                if (squarewidth == 0)
                    return;
                g.FillPie(new SolidBrush(Color.FromArgb(Alpha, FillColor)),
                          new Rectangle((int)(CenterPoint.X - squarewidth / 2),
                                        (int)(CenterPoint.Y - squarewidth / 2),
                                        squarewidth,
                                        squarewidth),
                          start,
                          end);

                g.FillPie(new SolidBrush(Color.FromArgb(Alpha, SecondColor)),
                          new Rectangle((int)(CenterPoint.X - squarewidth / 2),
                                        (int)(CenterPoint.Y - squarewidth / 2),
                                        squarewidth,
                                        squarewidth),
                          EndAngle,
                          360 - end);
            }
            
        }
    }
}
